package com.kevinwu.sqlSession;

import com.kevinwu.config.XMLConfigBuilder;
import com.kevinwu.pojo.Configuation;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {

        //使用dom4j解析配置文件，将内容封装到Configuration对象中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuation configuation = xmlConfigBuilder.parseConfig(in);

        //创建SqlSessionFactory对象
        DefaultSqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuation);

        return  sqlSessionFactory;
    }
}
